package rollercoaster.railway.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import rollercoaster.commons.Vertex3D;
import rollercoaster.railway.interfaces.IPolePosition;

public class PolePosition implements IPolePosition{
	
	private String filepath;
	
	public PolePosition(){
		
	}
	
	public PolePosition(String filepath){
		this.filepath = filepath;
	}
	
	public List<Float> getPolePositions(String filepath){
		this.filepath = filepath;
		return getPolePositions();
	}

	public List<Float> getPolePositions() {
		try {
			BufferedReader reader = new BufferedReader(new FileReader(new File(filepath)));
			ArrayList<Float> list = new ArrayList<Float>();
			String line;
			String[] vertex;
			
			//Skip bullshit in obj file and reading things that matter
			while((line = reader.readLine()) != null){
				if(line.startsWith("t ")){
					vertex = line.split(" ");
					list.add(Float.parseFloat(vertex[1]));					
				}

			}
			
			reader.close();
			return list;
		
		} catch (FileNotFoundException e) {
			System.out.println("File not Found");
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			System.out.println("Error while reading File");
			e.printStackTrace();
			return null;
		}
	}

}
